﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace GameRobot
{
    public class SampleVirtualRobot : VirtualRobot
    {
        bool moving = false;

        public void MoveHead_sd()
        {
            _listMethodUsed.Add("MoveHead()");
            ///////////////////////////////////////////////////////////////
            GameMessage action = new GameMessage();
            action.message = messagedef.MoveHead;
            if (moving)
            {
                //StopMove();
            }
            moving = true;
            PushMessage(action);
            moving = false;
        }

        public void MoveBack_sd()
        {
            _listMethodUsed.Add("MoveBack()");
            ///////////////////////////////////////////////////////////////
            GameMessage action = new GameMessage();
            action.message = messagedef.MoveBack;
            if (moving)
            {
                //StopMove();
            }
            moving = true;
            PushMessage(action);
            moving = false;
        }

        public void MoveRight_sd()
        {
            _listMethodUsed.Add("MoveRight()");
            ///////////////////////////////////////////////////////////////
            GameMessage action = new GameMessage();
            action.message = messagedef.MoveRight;
            if (moving)
            {
                //StopMove();
            }
            moving = true;
            PushMessage(action);
            moving = false;
        }
        public void MoveLeft_sd()
        {
            _listMethodUsed.Add("MoveLef()");
            ///////////////////////////////////////////////////////////////
            GameMessage action = new GameMessage();
            action.message = messagedef.MoveLeft;
            if (moving)
            {
                //StopMove();
            }
            moving = true;
            PushMessage(action);
            moving = false;
        }
        public void MoveAhead_sd(float range)
        {
            _listMethodUsed.Add("MoveAhead(" + range.ToString() + ")");
            ///////////////////////////////////////////////////////////////
            GameMessage action = new GameMessage();
            action.message = messagedef.MoveAhead;
            action.param1 = range;
            if (moving)
            {
                //StopMove();
            }
            moving = true;
            PushMessage(action);
            moving = false;
        }

        private bool CheckTimeOut(string functionname)
        {
            if (RobotSetting.timeout)
            {
                if (_controlType == ControlType.ProgrammingControl)
                {
                    //throw new NotImplementedException();
                    //MessageBox.Show("you cannot use " + functionname);
                    //return true;
                }
            }
            return false;
        }

        //public virtual void AdvanceMove_sd()
        //{
        //    if (CheckTimeOut("AdvanceMove()"))
        //        return;
        //    MoveAhead_sd(-100.0f);
        //}

        //public void Turn_sd(float angle)
        //{
        //    _listMethodUsed.Add("Turn(" + angle.ToString() + ")");
        //    ///////////////////////////////////////////////////////////////
        //    GameMessage action = new GameMessage();
        //    action.message = messagedef.Turn;
        //    action.param1 = angle;
        //    if (moving)
        //    {
        //        //StopTurn();
        //    }
        //    moving = true;
        //    PushMessage(action);
        //    moving = false;
        //}

        public bool AheadIsEmpty()
        {
            return true;
        }

        public bool LeftIsEmpty()
        {
            return true;
        }

        public bool RightIsEmpty()
        {
            return true;
        }

        public void StopTurn()
        {
            GameMessage action = new GameMessage();
            action.message = messagedef.StopTurn;
            PushMessage(action);
        }

        public void StopMove()
        {
            GameMessage action = new GameMessage();
            action.message = messagedef.StopMove;
            PushMessage(action);            
        }

        public PointF GetPosition()
        {
            GameMessage action = new GameMessage();
            action.message = messagedef.GetPosition;
            PushMessage(action);
            action = PopMessage(false);
            return new PointF((float)action.param1, (float)action.param2);
        }

        public override void ParseMessage(GameMessage message)
        {
            switch (message.message)
            {
                case messagedef.CompleteMove:
                    CompleteMove_event(null, null);
                    break;
            }
        }

        public virtual void CompleteMove_event(object sender, object e)
        {

        }
    }
}
